home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 November: Tool Chest / Dev.CD Nov 94.toast / Tool Chest / Testing & Debugging / Virtual User tools / Memory Monitor 1.0.3 / MemoryMonitor.vulib < prev   
Encoding:
Text File  |  1994-06-15  |  13.6 KB  |  405 lines  |  [TEXT/MPS ]

  1. #######################################################################################
  2. #    InitMemoryMonitor( OnTarget := false )
  3. #
  4. #    Prepares Memory Monitor as an external tool.
  5. #
  6. # Input:
  7. #
  8. #    OnTarget
  9. #        Pass in true if Memory Monitor is to run on a target, false for the Host.
  10. #        By default Memory Monitor runs on the Host
  11. #    
  12. #######################################################################################
  13. Task InitMemoryMonitor( OnTarget := false )
  14. Begin
  15.     x := MemoryMonitor( "Initialize", OnTarget );
  16.     Script_Error := ScriptError();
  17.     return { x[1], x[2], x[3], Script_Error };
  18. end;
  19.  
  20.  
  21. #######################################################################################
  22. #    QuitMemoryMonitor()
  23. #
  24. #    Causes Memory Monitor application to 'Quit'.
  25. #
  26. #######################################################################################
  27. Task QuitMemoryMonitor()
  28. Begin
  29.     x := MemoryMonitor( "Quit" );
  30.     Script_Error := ScriptError();
  31.     return { x[1], x[2], x[3], Script_Error };
  32. end;
  33.  
  34.  
  35. #######################################################################################
  36. #    GetAllProcesses( pCallAsync := false )
  37. #
  38. #    Returns a list of all processes which are currently running.
  39. #
  40. # Input:
  41. #
  42. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  43. #
  44. # Output:
  45. #
  46. #    The return value is a list of ProcessRecord elements: { ProcRec, ProcRec, ... }
  47. #    Each ProcessRecord element is a list containing the following elements
  48. #    
  49. # Index    Data Type    Label        Significance
  50. # ----- ---------   -----       ------------
  51. #    1    string        Name        The name of the process        
  52. #    2    string        Type        The 4 letter type code    
  53. #    3    string        Signature    The 4 letter signature code        
  54. #    4    string        Location    Decimal digits of address of the heap zone
  55. #    5    string        Size        Decimal digits of heap zone size in bytes
  56. #    6    string        Free        Decimal digits of Free Memory in bytes
  57. #    7    string        Pathname    Pathname to the file from which the process came
  58. #    
  59. #######################################################################################
  60. Task GetAllProcesses( pCallAsync := false )
  61. Begin
  62.     x := MemoryMonitor( "GetAllProcesses" ) Async:pCallAsync;
  63.     Script_Error := ScriptError();
  64.     return { x[1], x[2], x[3], Script_Error };
  65. end;
  66.  
  67.  
  68. #######################################################################################
  69. #    GetProcessInfo( ProcName, pCallAsync := false )
  70. #
  71. #    Returns Process Manager information for the process specified
  72. #    by the ProcName paramter
  73. #
  74. # Input:
  75. #
  76. #    ProcName    string        The name of the process of interest
  77. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  78. #
  79. # Output:
  80. #
  81. #    return value is a ProcessRecord containing the following elements
  82. #    
  83. # Index    Data Type    Label        Significance
  84. # ----- ---------   -----       ------------
  85. #    1    string        Name        The name of the process        
  86. #    2    string        Type        The 4 letter type code    
  87. #    3    string        Signature    The 4 letter signature code        
  88. #    4    string        Location    Decimal digits of address of the heap zone
  89. #    5    string        Size        Decimal digits of heap zone size in bytes
  90. #    6    string        Free        Decimal digits of Free Memory in bytes
  91. #    7    string        Pathname    Pathname to the file from which the process came
  92. #    
  93. #######################################################################################
  94. Task GetProcessInfo( ProcName, pCallAsync := false )
  95. Begin
  96.     x := MemoryMonitor( "GetProcessInfo", ProcName ) Async:pCallAsync;
  97.     Script_Error := ScriptError();
  98.     return { x[1], x[2], x[3], Script_Error };
  99. end;
  100.  
  101.  
  102. #######################################################################################
  103. #    GetZoneMap(  ZoneSelector, pCallAsync := false )
  104. #
  105. #    Returns a list containing location and size info for the specified zone 
  106. #    and all zones nested within the specified zone.
  107. #
  108. # Input:
  109. #
  110. #    ZoneSelector        Determines which heap zone, may be of two forms:
  111. #
  112. #    Form 1:    string        
  113. #        The process/zone name        
  114. #            
  115. #        Example 'Finder'    - the Finder's heap zone
  116. #            
  117. #    Form 2: { string [[,integer] ...] }    
  118. #        Element 1 determines the root heap zone 
  119. #        Each following index specifies which nested heap zone
  120. #
  121. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  122. #
  123. #        There are two names which can be used in the place of a prcess name
  124. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  125. #        to the two root heap zones.
  126. #
  127. #        Example { 'System', 1 } - The first nested heap within the System heap.
  128. #
  129. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  130. #
  131. # Output:
  132. #
  133. #    The return value is a list of ZoneRecord elements: { ZoneLoc, ZoneLoc, ... }
  134. #    Note the fourth element is a list which may contain more ZoneRecord elements.
  135. #    Since heap zones can be nested, ZoneRecords can also be nested.
  136. #    
  137. # Index    Data Type    Label            Significance
  138. # ----- ---------   -----           ------------
  139. #    1    string        StartAddress    Decimal digits of address where heap zone begins
  140. #    2    string        EndAddress        Decimal digits of address where heap zone ends
  141. #    3    string        Size            Decimal digits of size of the heap zone in bytes
  142. #    4    list        NestedZones        List of all nested heap zones
  143. #    
  144. #######################################################################################
  145. Task GetZoneMap(  ZoneSelector := "", pCallAsync := false )
  146. Begin
  147.     x := MemoryMonitor( "GetZoneMap", ZoneSelector ) Async:pCallAsync;
  148.     Script_Error := ScriptError();
  149.     return { x[1], x[2], x[3], Script_Error };
  150. end;
  151.  
  152.  
  153. #######################################################################################
  154. #    GetZoneTotals( ZoneSelector, pCallAsync := false )
  155. #
  156. #    Returns a summary of how memory is allocated within a specified heap zone.
  157. #    The total bytes and number of blocks is returned for each of the following
  158. #    catagories : 
  159. #        Free,  
  160. #        Relocatable,  
  161. #        Non-Relocatable,   
  162. #        Non-Relocatable/Locked, 
  163. #        Non-Relocatable/Not Locked & Purgable
  164. #    
  165. #    This is similar to Macsbug's HT (heap totals) command
  166. #
  167. # Input:
  168. #
  169. #    ZoneSelector        Determines which heap zone, may be of two forms:
  170. #
  171. #    Form 1:    string        
  172. #        The process/zone name        
  173. #            
  174. #        Example 'Finder'    - the Finder's heap zone
  175. #            
  176. #    Form 2: { string [[,integer] ...] }    
  177. #        Element 1 determines the root heap zone 
  178. #        Each following index specifies which nested heap zone
  179. #
  180. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  181. #
  182. #        There are two names which can be used in the place of a prcess name
  183. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  184. #        to the two root heap zones.
  185. #
  186. #        Example { 'System', 1 } - The first nested heap within the System heap.
  187. #
  188. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  189. #
  190. # Output:
  191. #
  192. #    return value is a list of one element for each catagory of block allocation type
  193. #    Each element is itself a list containing two values, number of blocks and total bytes 
  194. #    'number of blocks' is an integer value, and 'total bytes' is a string of decimal digits
  195. #    
  196. # Index    Data Type    Label        Significance
  197. # ----- ---------   -----       ------------
  198. #    1    list        Free                                    { number of blocks, total bytes }
  199. #    2    list        Relocatable                                { number of blocks, total bytes }
  200. #    3    list        Non-Relocatable                            { number of blocks, total bytes }
  201. #    4    list        Non-Relocatable/Locked                    { number of blocks, total bytes }
  202. #    5    list        Non-Relocatable/Not Locked & Purgable    { number of blocks, total bytes }
  203. #    6    list        Total                                    { number of blocks, total bytes }
  204. #    
  205. #######################################################################################
  206. Task GetZoneTotals( ZoneSelector, pCallAsync := false )
  207. Begin
  208.     x := MemoryMonitor( "GetZoneTotals", ZoneSelector ) Async:pCallAsync;
  209.     Script_Error := ScriptError();
  210.     return { x[1], x[2], x[3], Script_Error };
  211. end;
  212.  
  213.  
  214. #######################################################################################
  215. #    CheckZone( ZoneSelector, pCallAsync := false )
  216. #
  217. #    Checks the Memory Manager data structures within the specified heap zone
  218. #    Returns true if no inconsistencies are found.
  219. #    
  220. #    This is similar to Macsbug's HC (heap check) command
  221. #
  222. # Input:
  223. #
  224. #    ZoneSelector        Determines which heap zone, may be of two forms:
  225. #
  226. #    Form 1:    string        
  227. #        The process/zone name        
  228. #            
  229. #        Example 'Finder'    - the Finder's heap zone
  230. #            
  231. #    Form 2: { string [[,integer] ...] }    
  232. #        Element 1 determines the root heap zone 
  233. #        Each following index specifies which nested heap zone
  234. #
  235. #        Example { 'Virtual User', 1 } - first nested heap zone within Virtual User
  236. #
  237. #        There are two names which can be used in the place of a prcess name
  238. #        'SystemZone' and 'MultiFinderZone'. These values allow access  
  239. #        to the two root heap zones.
  240. #
  241. #        Example { 'System', 1 } - The first nested heap within the System heap.
  242. #
  243. #    pCallAsync    boolean        Determines wheather the tool is called asynchronously
  244. #
  245. # Output:
  246. #
  247. #    The return value is a symbol : either true or false
  248. #    
  249. #######################################################################################
  250. Task CheckZone( ZoneSelector, pCallAsync := false )
  251. Begin
  252.     x := MemoryMonitor( "CheckZone", ZoneSelector ) Async:pCallAsync;
  253.     Script_Error := ScriptError();
  254.     return { x[1], x[2], x[3], Script_Error };
  255. end;
  256.  
  257.  
  258.  
  259. #######################################################################################
  260. #    GetAboutThisMacintosh( pCallAsync := false )
  261. #
  262. #    Returns information contained in the "About this Macintosh" box.
  263. #    
  264. # Input:
  265. #
  266. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  267. #
  268. # Output:
  269. #
  270. #    The return value is a list of items from Finder's About Box ( "About This Macintosh" ).
  271. #    Each element of the list is as follows:
  272. #
  273. # Index    Data Type    Label            Significance
  274. # ----- ---------   -----              ------------
  275. #    1    string        PhysicalRAM        Decimal digits of 'Built-in Memory'
  276. #    2    string        LogicalRAM        Decimal digits of 'Total Memory'
  277. #    3    string        LargestBlock    Decimal digits of 'Largest unused block'
  278. #    4    list        Processes        List of info for each process
  279. #    
  280. #    The 'Processes' element is a list containing one of the following records 
  281. #    for each process.
  282. #
  283. # Index    Data Type    Label            Significance
  284. # ----- ---------   -----              ------------
  285. #    1    string        Name            Process name
  286. #    2    string        LargestBlock    Decimal digits of process size in bytes
  287. #
  288. #######################################################################################
  289. Task GetAboutThisMacintosh( pCallAsync := false )
  290. Begin
  291.     x := MemoryMonitor( "GetAboutThisMacintosh" ) Async:pCallAsync;
  292.     Script_Error := ScriptError();
  293.     return { x[1], x[2], x[3], Script_Error };
  294. end;
  295.  
  296. #######################################################################################
  297. #    ReadBytes( pAddress, pCount, pCallAsync := false )
  298. #
  299. #    Returns a list of contiguous bytes from memory
  300. #    
  301. # Input:
  302. #
  303. #    pAddress        list        The location of the first byte to read.
  304. #                                The list must contain the High & Low words of the address
  305. #
  306. #    pCount            integer        The number of bytes to read
  307. #
  308. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  309. #
  310. # Output:
  311. #
  312. #    The return value is a list of integers.
  313. #    Each one is equal to the value of the byte read from memory.
  314. #
  315. #######################################################################################
  316. Task ReadBytes( pAddress, pCount, pCallAsync := false )
  317. Begin
  318.     x := MemoryMonitor( "ReadBytes", pAddress, pCount ) Async:pCallAsync;
  319.     Script_Error := ScriptError();
  320.     return { x[1], x[2], x[3], Script_Error };
  321. end;
  322.  
  323. #######################################################################################
  324. #    MacsbugCmd( Commands, Label := "Memory Moniotr", RemainInMacsBug := false, pCallAsync := false )
  325. #
  326. #    Executes a Macsbug command, via Macsbug command line
  327. #    
  328. # Input:
  329. #
  330. #    Commands        string        One or more Macsbug commands, separated by semi-colons.
  331. #
  332. #    Label            string        Optional label which is desplayed in Macsbug,
  333. #                                prior to command line execution
  334. #
  335. #    RemainInMacsBug    string        if false, a "Go" command is appended to the command line
  336. #                                otherwise, no "Go" command is appeded. This makes it possible
  337. #                                to remain in Macsbug ( for what ever reason )
  338. #
  339. #    pCallAsync        boolean        Determines wheather the tool is called asynchronously
  340. #
  341. # Output:
  342. #
  343. #    The return value is the 'true' symbol if successful, otherwise 'undefined'
  344. #
  345. #######################################################################################
  346. Task MacsbugCmd( CommandLine, Label := "Memory Monitor", RemainInMacsBug := false, pCallAsync := false )
  347. Begin
  348.         ###    Append a "Go" command so we won't stay in Macsbug
  349.     if RemainInMacsBug
  350.     begin
  351.         CommandLine := "{Label}; {CommandLine}";
  352.     end;
  353.     else
  354.     begin
  355.         CommandLine := "{Label}; {CommandLine} ;g";
  356.     end;
  357.     
  358.     x := MemoryMonitor( "MacsbugCmd", CommandLine ) Async:pCallAsync;
  359.     Script_Error := ScriptError();
  360.     return { x[1], x[2], x[3], Script_Error };
  361. end;
  362.  
  363.  
  364. #######################################################################################
  365. #    MemoryMonitor Tool Declaration
  366. #
  367. #    Defines the V.U. scripting interface to Memory Monitor
  368. #
  369. Tool MemoryMonitor s:'MMTL'
  370. begin
  371.         #####################################################
  372.         ### Services specific to Memory Monitor:
  373.     
  374.         ### Process Manager
  375.     Service "GetAllProcesses"( )                 return 'list';
  376.     Service "GetProcessInfo"( )                 return 'list';
  377.  
  378.         ### Heap Zone
  379.     Service "GetZoneMap"( 'undefined' )            return 'list';
  380.     Service "GetZoneTotals"( 'undefined' )        return 'list';
  381.     Service "CheckZone"( 'undefined' )            return 'symbol';
  382.  
  383.         ### Finder's About Box
  384.     Service "GetAboutThisMacintosh"( )            return 'list';
  385.  
  386.         ### Reading Memory
  387.     Service "ReadBytes"( 'list', 'integer' )    return 'list';
  388.  
  389.         ### Macsbug Command
  390.     Service "MacsbugCmd"( 'string' )            return 'symbol';
  391.     
  392.         #####################################################
  393.         ### Services common to all Virtual User external tools:
  394.     
  395.     Service "Initialize"        ( 'undefined' );
  396.     Service "Cancel"            ( 'string' );
  397.     Service "Poll"                ( 'string' )     return 'string';
  398.     Service "ServiceSupported"    ( 'string' )     return 'undefined';
  399.     Service "GetToolServices"    ()                 return 'list';
  400.     Service "GetToolVersion"    ()                 return 'list';
  401.     Service "Quit"();
  402.  
  403. end;
  404.  
  405.